package cn.edu.neu.softlab633.influencemaximization.sy;

import cn.edu.neu.softlab633.influencemaximization.sy.CELF_Algorithm.CELF_Algorithm;
import cn.edu.neu.softlab633.influencemaximization.sy.M_TLTGreedy.M_TLTGreedy;
import cn.edu.neu.softlab633.influencemaximization.sy.bean.Graph;
import cn.edu.neu.softlab633.influencemaximization.sy.datapreprocessing.ConstantTopic;
import cn.edu.neu.softlab633.influencemaximization.sy.input.GraphReader;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by Jason on 2017/5/14.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new FileWriter("data/result.txt"));
        String g1_filepath = "data/FT/facebook_network_topic_1.csv";
        String g2_filepath = "data/FT/twitter_network_topic_1.csv";
        String alignment_filepath = "data/FT/alignment_topic_1.csv";
        Double[] query = new Double[ConstantTopic.topicNum];
        for (int i = 0; i < ConstantTopic.topicNum; i++) {
            query[i] = 0.0;
        }
        query[0] = 1.0;
//        query[3] = 0.4;
        double threshold = 0.2;
        int k = 10;
        int p = 4;
        long start = System.currentTimeMillis();
//        Graph graph = GraphReader.graphReaderTest();
        System.out.println("读取文件");
        bw.write("读取文件....../reading file......");
        bw.newLine();
        Graph g = GraphReader.graphReaderTest();
        CELF_Algorithm.celfAlgorithm(threshold, query, k, g);
        Graph graph = GraphReader.readGraphFromCSV(g1_filepath, g2_filepath, alignment_filepath);
        long end = System.currentTimeMillis();
        System.out.println("    建立索引消耗时间：" + (end - start) + "毫秒");
        bw.write("  creat graph index: " + (end - start) + "ms");
        bw.newLine();

//        System.out.println("M-TLTGreedy:    k = " + k);
//        bw.write("M-TLTGreedy:    k = " + k);
//        bw.newLine();
//        start = System.currentTimeMillis();
//        int influence = M_TLTGreedy.getSeed(threshold, query, k, p, graph);
//        end = System.currentTimeMillis();
//        System.out.println("    M-TLTGreedy算法运行时间" + (end - start) + "ms");
//        bw.write("  influence spread:  " + influence);
//        bw.newLine();
//        bw.write("  M-TLTGreedy run time" + (end - start) + "ms");
//        bw.newLine();
//
        for (; k < 101; k += 10) {
            System.out.println("CELF:   k = " + k);
            bw.write("CELF:   k = " + k);
            bw.newLine();
            start = System.currentTimeMillis();
            int tmp = CELF_Algorithm.celfAlgorithm(threshold, query, k, graph);
            end = System.currentTimeMillis();
            System.out.println("    CELF算法运行时间：" + (end - start) + "ms");
            bw.write("    CELF influence spread: " + tmp);
            bw.newLine();
            bw.write("    CELF running time: " + (end - start) + "ms");
            bw.newLine();

            System.out.println("M-TLTGreedy:    k = " + k);
            bw.write("M-TLTGreedy:    k = " + k);
            bw.newLine();
            start = System.currentTimeMillis();
            tmp = M_TLTGreedy.getSeed(threshold, query, k, p, graph);
            end = System.currentTimeMillis();
            System.out.println("    M-TLTGreedy算法运行时间" + (end - start) + "ms");
            bw.write("    M-TLTGreedy influence spread: " + tmp);
            bw.newLine();
            bw.write("    M-TlTGreedy running time: " + (end - start) + "ms");
        }
        bw.close();
    }
}
